﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KillBill.Business.Entities;
using KillBill.Data.DataAccess;

namespace KillBill.Business.Modules.Administration
{
    public class SecurityManager
    {
        private KillBillEntities _context;

        public SecurityManager()
        {
            _context = new KillBillEntities();
        }

        #region Login

        public Employee LogIn(string employeeId, string password)
        {
            Employee employee;
            try
            {
                employee = _context.Employee
                    .Include("Person")
                    .Include("EmployeeRole")
                    .FirstOrDefault(e => e.EmployeeID == employeeId && e.Password == password && e.IsActive);

                if (employee != null)
                {
                    employee.Messages.Add(employee.Person.LastName + " " + employee.Person.FirstName);
                }
                else
                {
                    employee = new Employee();
                    employee.Messages.Add("La cédula o contraseña son incorrectos.");
                }

                employee.Success = true;

                return employee;
            }
            catch (Exception ex)
            {
                employee = new Employee();
                employee.Messages.Clear();
                employee.Messages.Add("Ocurrio un error al momento al tratar de ingresar al sistema.");
                employee.Messages.Add(ex.Message);
                employee.Success = false;
                return employee;
            }
        }

        #endregion


    }
}
